package com.qingke.easyjava.jdbc.command.impl;

import com.qingke.easyjava.jdbc.app.BeSuperDao;
import com.qingke.easyjava.jdbc.command.PlayerCommand;
import com.qingke.easyjava.jdbc.pojo.Player;
import com.qingke.easyjava.jdbc.pojo.Question;
import com.qingke.easyjava.jdbc.util.QingkeConsole;

public class AskCommand extends PlayerCommand {

    public AskCommand(Player player) {
        super(player);
    }

    @Override
    public void executePlayerCommand() {
        String content = QingkeConsole.askUserInput("请输入你的问题");
        int credit = QingkeConsole.askUserInputInt("请输入问题的奖励分值", false);
        
        if (credit > player.getScore()) {
            credit = player.getScore();
            QingkeConsole.println("输入分值超过当前用户分数！默认使用用户分数为奖励值");
        }
        
        Question question = new Question(-1, content, player, credit);
        new BeSuperDao().upsertQuestion(question);
        
        player.getQuestions().add(question);
        player.setScore(player.getScore() - credit);

        QingkeConsole.println("你的提问已经被记录！");
    }

}
